home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / scripts / plot / __plr__.m next >
Text File  |  1996-07-12  |  3KB  |  128 lines

  1. ## Copyright (C) 1996 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## Author: jwe
  21.  
  22. function __plr__ (theta, rho, fmt)
  23.  
  24.   if (nargin == 1)
  25.     [nr, nc] = size (theta);
  26.     if (nr == 1)
  27.       theta = theta.';
  28.       tmp = nr;
  29.       nr = nc;
  30.       nc = tmp;
  31.     endif
  32.     theta_i = imag (theta);
  33.     if (any (theta_i))
  34.       rho = theta_i;
  35.       theta = real (theta);
  36.     else
  37.       rho = theta;
  38.       theta = (1:nr)';
  39.     endif
  40.   endif
  41.  
  42.   if (nargin <= 2)
  43.     if (any (imag (theta)))
  44.       theta = real (theta);
  45.     endif
  46.     if (any (imag (rho)))
  47.       rho = real (rho);
  48.     endif
  49.     if (is_scalar (theta))
  50.       if (is_scalar (rho))
  51.         x = rho * cos (theta);
  52.         y = rho * sin (theta);
  53.         __plt2ss__ (x, y, fmt);
  54.       endif
  55.     elseif (is_vector (theta))
  56.       if (is_vector (rho))
  57.         if (length (theta) != length (rho))
  58.           error ("polar: vector lengths must match");
  59.         endif
  60.         if (rows (rho) == 1)
  61.           rho = rho.';
  62.         endif
  63.         if (rows (theta) == 1)
  64.           theta = theta.';
  65.         endif
  66.         x = rho .* cos (theta);
  67.         y = rho .* sin (theta);
  68.         __plt2vv__ (x, y, fmt);
  69.       elseif (is_matrix (rho))
  70.         [t_nr, t_nc] = size (theta);
  71.         if (t_nr == 1)
  72.           theta = theta.';
  73.           tmp = t_nr;
  74.           t_nr = t_nc;
  75.           t_nc = tmp;
  76.         endif
  77.         [r_nr, r_nc] = size (rho);
  78.         if (t_nr != r_nr)
  79.           rho = rho.';
  80.           tmp = r_nr;
  81.           r_nr = r_nc;
  82.           r_nc = tmp;
  83.         endif
  84.         if (t_nr != r_nr)
  85.           error ("polar: vector and matrix sizes must match");
  86.         endif
  87.         x = diag (cos (theta)) * rho;
  88.         y = diag (sin (theta)) * rho;
  89.         __plt2vm__ (x, y, fmt);
  90.       endif
  91.     elseif (is_matrix (theta))
  92.       if (is_vector (rho))
  93.         [r_nr, r_nc] = size (rho);
  94.         if (r_nr == 1)
  95.           rho = rho.';
  96.           tmp = r_nr;
  97.           r_nr = r_nc;
  98.           r_nc = tmp;
  99.         endif
  100.         [t_nr, t_nc] = size (theta);
  101.         if (r_nr != t_nr)
  102.           theta = rho.';
  103.           tmp = t_nr;
  104.           t_nr = t_nc;
  105.           t_nc = tmp;
  106.         endif
  107.         if (r_nr != t_nr)
  108.           error ("polar: vector and matrix sizes must match");
  109.         endif
  110.         diag_r = diag (r);
  111.         x = diag_r * cos (theta);
  112.         y = diag_r * sin (theta);
  113.         __plt2mv__ (x, y, fmt);
  114.       elseif (is_matrix (rho))
  115.         if (size (rho) != size (theta))
  116.           error ("polar: matrix dimensions must match");
  117.         endif
  118.         x = rho .* cos (theta);
  119.         y = rho .* sin (theta);
  120.         __plt2mm__ (x, y, fmt);
  121.       endif
  122.     endif
  123.   else
  124.     usage ("__plr__ (x [, y])");
  125.   endif
  126.  
  127. endfunction
  128.